package com.nt.oam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.nt.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nt.common.annotation.Log;
import com.nt.common.core.controller.BaseController;
import com.nt.common.core.domain.AjaxResult;
import com.nt.common.enums.BusinessType;
import com.nt.oam.domain.AntHospital;
import com.nt.oam.service.IAntHospitalService;
import com.nt.common.utils.poi.ExcelUtil;
import com.nt.common.core.page.TableDataInfo;

/**
 * 医院信息Controller
 *
 * @author JZFeng
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/oam/hospital")
public class AntHospitalController extends BaseController {
    @Autowired
    private IAntHospitalService antHospitalService;

    /**
     * 查询医院信息列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hospital:list')")
    @GetMapping("/list")
    public TableDataInfo list(AntHospital antHospital) {
        startPage();
        List<AntHospital> list = antHospitalService.selectAntHospitalList(antHospital);
        return getDataTable(list);
    }

    /**
     * 导出医院信息列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hospital:export')")
    @Log(title = "医院信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AntHospital antHospital) {
        List<AntHospital> list = antHospitalService.selectAntHospitalList(antHospital);
        ExcelUtil<AntHospital> util = new ExcelUtil<AntHospital>(AntHospital.class);
        util.exportExcel(response, list, "医院信息数据");
    }

    /**
     * 获取医院信息详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hospital:query')")
    @GetMapping(value = "/{hospitalId}")
    public AjaxResult getInfo(@PathVariable("hospitalId") Long hospitalId) {
        return success(antHospitalService.selectAntHospitalByHospitalId(hospitalId));
    }

    /**
     * 新增医院信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hospital:add')")
    @Log(title = "医院信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AntHospital antHospital) {
        return toAjax(antHospitalService.insertAntHospital(antHospital));
    }

    /**
     * 修改医院信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hospital:edit')")
    @Log(title = "医院信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AntHospital antHospital) {
        return toAjax(antHospitalService.updateAntHospital(antHospital));
    }

    /**
     * 删除医院信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hospital:remove')")
    @Log(title = "医院信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{hospitalIds}")
    public AjaxResult remove(@PathVariable Long[] hospitalIds) {
        return toAjax(antHospitalService.deleteAntHospitalByHospitalIds(hospitalIds));
    }

    /**
     * 获取页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hospital:query')")
    @GetMapping(value = "/get/isModify")
    public AjaxResult getHospitalModify(@RequestParam Long hospitalId) {
        return success(antHospitalService.selectHospitalModify(hospitalId));
    }

    /**
     * 修改页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hospital:edit')")
    @Log(title = "医院信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit/modify/{hospitalId}")
    public AjaxResult editModify(@PathVariable("hospitalId") Long hospitalId) {
        int isModify = 1;
        return toAjax(antHospitalService.updateHospitalModify(hospitalId, isModify));
    }
}
